package Pattern.FactoryPattern.workTest.Work.Program2;

interface ConvertorCreator {
    Convertor getConvertor();//(1)
}

interface Convertor {
    public String transform();
}

class DBConvertorCreator implements ConvertorCreator {
    public Convertor getConvertor() {
        return new DBConvertor();// (2)
    }
}

class TXTConvertorCreator implements ConvertorCreator {
    public Convertor getConvertor() {
        return new TXTConvertor();//(3)
    }
}

class DBConvertor implements Convertor {
    public String transform() {
        String str = "成功将数据库数据转换为XML格式";
        System.out.println(str);//实现代码省略
        return str;
    }
}

class TXTConvertor implements Convertor {
    public String transform() {
        String str ="成功将TXT数据转换为XML格式";
        System.out.println(str);//实现代码省略
        return str;
    }
}

class Test {
    public static void main(String args[]) {
        ConvertorCreator creator;
        Convertor convertor;//(4)
        creator = new DBConvertorCreator();
        convertor = creator.getConvertor();//(5)
        convertor.transform();
    }
}
